package com.qf.sl.youshare;

/**
 * Created by IDEA
 * User : sl
 * on 2015/2/7.
 * 17:03
 */

import com.qf.sl.youshare.model.Category;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * 数据存储区, 单例模式访问
 */
public class DataStorage {
    private static DataStorage ourInstance;

    public static DataStorage getInstance() {
        if (ourInstance == null) {
            ourInstance = new DataStorage();
        }
        return ourInstance;
    }

    /**
     * 存储引用程序中商城部分的分类信息
     */
    private HashMap<String, Category> storeCategories;

    private DataStorage() {
        storeCategories = new LinkedHashMap<String, Category>();
    }

    public void addCategories(Category category){
        if (category != null) {
            String id = category.getId();
            if (id != null) {
                storeCategories.put(id, category);
            }
        }
    }

    public Category getCategory(String id){
        Category ret = null;

        if (id != null) {
            if (storeCategories.containsKey(id)) {
                ret = storeCategories.get(id);
            }
        }

        return ret;
    }
}
